﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用

namespace OracleDAL.Common
{
    /// <summary>
    /// 数据访问类DXT_GROUP_CALL_H。
    /// </summary>
    public class DXT_GROUP_CALL_H
    {
        public DXT_GROUP_CALL_H()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string NE_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from DXT_GROUP_CALL_H");
            strSql.Append(" where NE_ID=:NE_ID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NE_ID", OracleType.VarChar,50)};
            parameters[0].Value = NE_ID;

            return OracleHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Model.Common.DXT_GROUP_CALL_H model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into DXT_GROUP_CALL_H(");
            strSql.Append("NE_ID,EQUIP_NAME,INDEX_NUM,NEW_TIME_CODE,NORM_GCALL_SHIFT_AREA_TIME,EMER_GCALL_SHIFT_AREA_TIME,NORM_GCALL_FIXED_AREA_TIME,EMER_GCALL_FIXED_AREA_TIME,START_TIME,STOP_TIME)");
            strSql.Append(" values (");
            strSql.Append(":NE_ID,:EQUIP_NAME,:INDEX_NUM,:NEW_TIME_CODE,:NORM_GCALL_SHIFT_AREA_TIME,:EMER_GCALL_SHIFT_AREA_TIME,:NORM_GCALL_FIXED_AREA_TIME,:EMER_GCALL_FIXED_AREA_TIME,:START_TIME,:STOP_TIME)");
            OracleParameter[] parameters = {
					new OracleParameter(":NE_ID", OracleType.VarChar,16),
					new OracleParameter(":EQUIP_NAME", OracleType.VarChar,100),
					new OracleParameter(":INDEX_NUM", OracleType.Number,4),
					new OracleParameter(":NEW_TIME_CODE", OracleType.DateTime),
					new OracleParameter(":NORM_GCALL_SHIFT_AREA_TIME", OracleType.Float,22),
					new OracleParameter(":EMER_GCALL_SHIFT_AREA_TIME", OracleType.Float,22),
					new OracleParameter(":NORM_GCALL_FIXED_AREA_TIME", OracleType.Float,22),
					new OracleParameter(":EMER_GCALL_FIXED_AREA_TIME", OracleType.Float,22),
					new OracleParameter(":START_TIME", OracleType.DateTime),
					new OracleParameter(":STOP_TIME", OracleType.DateTime)};
            parameters[0].Value = model.NE_ID;
            parameters[1].Value = model.EQUIP_NAME;
            parameters[2].Value = model.INDEX_NUM;
            parameters[3].Value = model.NEW_TIME_CODE;
            parameters[4].Value = model.NORM_GCALL_SHIFT_AREA_TIME;
            parameters[5].Value = model.EMER_GCALL_SHIFT_AREA_TIME;
            parameters[6].Value = model.NORM_GCALL_FIXED_AREA_TIME;
            parameters[7].Value = model.EMER_GCALL_FIXED_AREA_TIME;
            parameters[8].Value = model.START_TIME;
            parameters[9].Value = model.STOP_TIME;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Model.Common.DXT_GROUP_CALL_H model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update DXT_GROUP_CALL_H set ");
            strSql.Append("NE_ID=:NE_ID,");
            strSql.Append("EQUIP_NAME=:EQUIP_NAME,");
            strSql.Append("INDEX_NUM=:INDEX_NUM,");
            strSql.Append("NEW_TIME_CODE=:NEW_TIME_CODE,");
            strSql.Append("NORM_GCALL_SHIFT_AREA_TIME=:NORM_GCALL_SHIFT_AREA_TIME,");
            strSql.Append("EMER_GCALL_SHIFT_AREA_TIME=:EMER_GCALL_SHIFT_AREA_TIME,");
            strSql.Append("NORM_GCALL_FIXED_AREA_TIME=:NORM_GCALL_FIXED_AREA_TIME,");
            strSql.Append("EMER_GCALL_FIXED_AREA_TIME=:EMER_GCALL_FIXED_AREA_TIME,");
            strSql.Append("START_TIME=:START_TIME,");
            strSql.Append("STOP_TIME=:STOP_TIME");
            strSql.Append(" where NE_ID=:NE_ID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NE_ID", OracleType.VarChar,16),
					new OracleParameter(":EQUIP_NAME", OracleType.VarChar,100),
					new OracleParameter(":INDEX_NUM", OracleType.Number,4),
					new OracleParameter(":NEW_TIME_CODE", OracleType.DateTime),
					new OracleParameter(":NORM_GCALL_SHIFT_AREA_TIME", OracleType.Float,22),
					new OracleParameter(":EMER_GCALL_SHIFT_AREA_TIME", OracleType.Float,22),
					new OracleParameter(":NORM_GCALL_FIXED_AREA_TIME", OracleType.Float,22),
					new OracleParameter(":EMER_GCALL_FIXED_AREA_TIME", OracleType.Float,22),
					new OracleParameter(":START_TIME", OracleType.DateTime),
					new OracleParameter(":STOP_TIME", OracleType.DateTime)};
            parameters[0].Value = model.NE_ID;
            parameters[1].Value = model.EQUIP_NAME;
            parameters[2].Value = model.INDEX_NUM;
            parameters[3].Value = model.NEW_TIME_CODE;
            parameters[4].Value = model.NORM_GCALL_SHIFT_AREA_TIME;
            parameters[5].Value = model.EMER_GCALL_SHIFT_AREA_TIME;
            parameters[6].Value = model.NORM_GCALL_FIXED_AREA_TIME;
            parameters[7].Value = model.EMER_GCALL_FIXED_AREA_TIME;
            parameters[8].Value = model.START_TIME;
            parameters[9].Value = model.STOP_TIME;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string NE_ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from DXT_GROUP_CALL_H ");
            strSql.Append(" where NE_ID=:NE_ID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NE_ID", OracleType.VarChar,50)};
            parameters[0].Value = NE_ID;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Common.DXT_GROUP_CALL_H GetModel(string NE_ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NE_ID,EQUIP_NAME,INDEX_NUM,NEW_TIME_CODE,NORM_GCALL_SHIFT_AREA_TIME,EMER_GCALL_SHIFT_AREA_TIME,NORM_GCALL_FIXED_AREA_TIME,EMER_GCALL_FIXED_AREA_TIME,START_TIME,STOP_TIME from DXT_GROUP_CALL_H ");
            strSql.Append(" where NE_ID=:NE_ID ");
            OracleParameter[] parameters = {
					new OracleParameter(":NE_ID", OracleType.VarChar,50)};
            parameters[0].Value = NE_ID;

            Model.Common.DXT_GROUP_CALL_H model = new Model.Common.DXT_GROUP_CALL_H();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.NE_ID = ds.Tables[0].Rows[0]["NE_ID"].ToString();
                model.EQUIP_NAME = ds.Tables[0].Rows[0]["EQUIP_NAME"].ToString();
                if (ds.Tables[0].Rows[0]["INDEX_NUM"].ToString() != "")
                {
                    model.INDEX_NUM = int.Parse(ds.Tables[0].Rows[0]["INDEX_NUM"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NEW_TIME_CODE"].ToString() != "")
                {
                    model.NEW_TIME_CODE = DateTime.Parse(ds.Tables[0].Rows[0]["NEW_TIME_CODE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NORM_GCALL_SHIFT_AREA_TIME"].ToString() != "")
                {
                    model.NORM_GCALL_SHIFT_AREA_TIME = decimal.Parse(ds.Tables[0].Rows[0]["NORM_GCALL_SHIFT_AREA_TIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["EMER_GCALL_SHIFT_AREA_TIME"].ToString() != "")
                {
                    model.EMER_GCALL_SHIFT_AREA_TIME = decimal.Parse(ds.Tables[0].Rows[0]["EMER_GCALL_SHIFT_AREA_TIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NORM_GCALL_FIXED_AREA_TIME"].ToString() != "")
                {
                    model.NORM_GCALL_FIXED_AREA_TIME = decimal.Parse(ds.Tables[0].Rows[0]["NORM_GCALL_FIXED_AREA_TIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["EMER_GCALL_FIXED_AREA_TIME"].ToString() != "")
                {
                    model.EMER_GCALL_FIXED_AREA_TIME = decimal.Parse(ds.Tables[0].Rows[0]["EMER_GCALL_FIXED_AREA_TIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["START_TIME"].ToString() != "")
                {
                    model.START_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["START_TIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["STOP_TIME"].ToString() != "")
                {
                    model.STOP_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["STOP_TIME"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NE_ID,EQUIP_NAME,INDEX_NUM,NEW_TIME_CODE,NORM_GCALL_SHIFT_AREA_TIME,EMER_GCALL_SHIFT_AREA_TIME,NORM_GCALL_FIXED_AREA_TIME,EMER_GCALL_FIXED_AREA_TIME,START_TIME,STOP_TIME ");
            strSql.Append(" FROM DXT_GROUP_CALL_H ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by NE_ID,NEW_TIME_CODE");
            return OracleHelper.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(DateTime STARTTIME, DateTime ENDTIME)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select NE_ID,EQUIP_NAME,INDEX_NUM,NEW_TIME_CODE,NORM_GCALL_SHIFT_AREA_TIME,EMER_GCALL_SHIFT_AREA_TIME,NORM_GCALL_FIXED_AREA_TIME,EMER_GCALL_FIXED_AREA_TIME,START_TIME,STOP_TIME ");
            strSql.Append(" FROM DXT_GROUP_CALL_H ");
            strSql.Append(" where START_TIME>=:STARTTIME and  STOP_TIME<=:ENDTIME");
            OracleParameter[] parameters = {
					new OracleParameter(":STARTTIME", OracleType.DateTime),
                                           new OracleParameter (":ENDTIME",OracleType .DateTime )};
            parameters[0].Value = STARTTIME;
            parameters[1].Value = ENDTIME;
            return OracleHelper.Query(strSql.ToString(), parameters);
        }
        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "DXT_GROUP_CALL_H";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}

